<template>
  <div class="banxin">
    <el-breadcrumb separator="/" style="padding: 20px 0;">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>文章列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="author" label="作者" width="200" />
      <el-table-column label="文章标题">
        <template v-slot="scope">
          <router-link :to="`/detail/${scope.row.id}`">{{scope.row.title}}</router-link>
        </template>
      </el-table-column>
      <el-table-column prop="date" label="日期" width="200" />
    </el-table>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { listApi } from '../request/api'
import moment from 'moment'

// 声明一个表格数组
const tableData = ref([])

onMounted(() => {
  listApi().then(res => {
      res.data.forEach(item=>{
        item.date = moment(item.date).startOf('day').fromNow();
      })
    if (res.errCode === 0) {
      tableData.value = res.data;
    }
  })
})
</script>

<style scoped lang='less'>
</style>